package main

import (
	"fmt"
	"sync"
)

type httpPkg struct{}

func (httpPkg) Get(url string) {}

var http httpPkg

func main() {
	var wg sync.WaitGroup
	var urls = []string{
		"http://www.baidu.com",
		"http://dev.go",
	}

	for _, url := range urls {
		wg.Add(1)
		go func(url string) {
			defer wg.Done()
			http.Get(url)
		}(url)
	}
	wg.Wait()
	fmt.Println("完成")
	exampleImplWaitGroup()
}

func exampleImplWaitGroup() {
	done := make(chan struct{}) //收取10份保护费
	count := 10
	for i := 0; i < count; i++ {
		go func(i int) {
			defer func() {
				done <- struct{}{}
			}()
			fmt.Printf("马仔%d号收保护费\n", i)
		}(i)
	}
	for j := 0; j < count; j++ {
		<-done
		fmt.Printf("马仔%d号已经收完保护费\n", j)
	}
	fmt.Println("所有马仔已经干完活了，开始酒吧消费～")
}
